<template>
  <div>
    <el-page-header @back="gomove" :content="pageTitle"></el-page-header>
    <el-divider content-position="left">
      <h3>录取情况</h3>
    </el-divider>
    <el-card class="box-card">
      <el-form label-position="right" label-width="80px" :model="dataForm" :rules="rules" ref="ruleForm">
        <el-form-item label="是否录取" class="wds-frame-form-item" label-width="120px" prop="enrollStatus">
          <el-select v-model="dataForm.enrollStatus" placeholder="请选择是否录取" clearable>
            <el-option
              v-for="item in enrollStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="录取时间" class="wds-frame-form-item" label-width="120px"
                      v-if="enrollVisible === dataForm.enrollStatus">
          <el-date-picker
            v-model="dataForm.enrollTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择录取时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入职状态" class="wds-frame-form-item" label-width="120px"
                      v-if="enrollVisible === dataForm.enrollStatus">
          <el-select v-model="dataForm.entryStatus" placeholder="请选择入职状态" clearable>
            <el-option
              v-for="item in entryStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入职时间" class="wds-frame-form-item" label-width="120px"
                      v-if="entryVisible === dataForm.entryStatus">
          <el-date-picker
            v-model="dataForm.entryTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择入职时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="未入职原因" class="wds-frame-form-item" label-width="120px"
                      v-if="entryVisible !== dataForm.entryStatus && enrollVisible === dataForm.enrollStatus">
<!--          <el-select v-model="dataForm.notEmployReason" placeholder="请选择未入职原因" clearable >-->
<!--            <el-option-->
<!--              v-for="item in notEmployReason"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value">-->
<!--            </el-option>-->
<!--          </el-select>-->
          <el-input v-model="dataForm.notEmployReason" placeholder="请输入未入职原因" style="width: 400px" clearable></el-input>
        </el-form-item>
        <el-form-item label="入职部门" class="wds-frame-form-item" label-width="120px"
                      v-if="entryVisible === dataForm.entryStatus">
          <el-select v-model="dataForm.entryOrganization" placeholder="请选择入职部门" clearable>
            <el-option
              v-for="item in entryOrganization"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="wds-frame-form-item" >
          <el-button type="primary" @click="submitForm('ruleForm')" class="button">录入</el-button>
          <el-button @click="resetForm('ruleForm')" class="button">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data(){
    return {
      pageIndex: 1,
      pageSize: 10,
      enrollVisible: 1,
      entryVisible: 1,
      enrollStatus:[{
        value: 0,
        label: '未录取'
      },{
        value: 1,
        label: '已录取'
      }],
      notEmployReason: [{
        value: '无',
        label: '无'
      },{
        value: '临时有安排 暂时不能来入职',
        label: '临时有安排 暂时不能来入职'
      }],
      entryStatus:[{
        value: 0,
        label: '未入职'
      },{
        value: 1,
        label: '已入职'
      }],
      entryOrganization: [],
      interviewId: '',
      infoForm: {
        interviewName: '',
        station:''
      },
      pageTitle: '',
      dataForm: {
        enrollStatus: '',
        enrollTime: '',
        entryStatus: '',
        entryTime: '',
        notEmployReason: '',
        entryOrganization: ''
      },
      rules:{
        enrollStatus:[{required: true, message: '请选择录取情况', trigger: 'blur'}]
      }
    }
  },
  created() {
    this.getOrgannization();
  },
  methods: {
    gomove () {
      this.$emit('gomove');
    },
    init(id){

      this.interviewId = id;
      console.log("123ssss"+this.interviewId)

      this.getInterviewRecords(id)
    },
    submitForm(ruleForm) {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/interview/interviewRecords/checkResult`),
            method: 'post',
            data: this.$http.adornData({
              'interviewId': this.interviewId,
              'enrollStatus': this.dataForm.enrollStatus,
              'enrollTime': this.dataForm.enrollTime,
              'entryStatus': this.dataForm.entryStatus || undefined,
              'entryTime': this.dataForm.entryTime || undefined,
              'notEmployReason': this.dataForm.notEmployReason || undefined,
              'entryOrganization': this.dataForm.entryOrganization || undefined
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: data.msg,
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 获取所有部门信息
    getOrgannization(){
      this.$http({
        url: this.$http.adornUrl(`/sys/organizations/list`),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.entryOrganization = data.page.list.map(item => ({
            value: item.name,
            label: item.name
          }))
          //console.log(this.interviewerList)
        }
      })
    },
    // 通过Id查询当前的面试记录
    getInterviewRecords(id){
      this.$http({
        url: this.$http.adornUrl(`/interview/interviewRecords/info/${this.interviewId}`),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.infoForm.interviewName = data.interviewRecords.name
          this.infoForm.station = data.interviewRecords.station
          this.dataForm.enrollStatus = data.interviewRecords.enrollStatus
          this.dataForm.enrollTime = data.interviewRecords.enrollTime
          this.dataForm.entryStatus = data.interviewRecords.entryStatus
          this.dataForm.entryTime = data.interviewRecords.entryTime
          this.dataForm.notEmployReason = data.interviewRecords.notEmployReason
          this.dataForm.entryOrganization = data.interviewRecords.entryOrganization
          this.pageTitle = '录取审核' + ':' + this.infoForm.interviewName + ':' + this.infoForm.station
        }
      })
    }


  }
}
</script>

<style >
.box-card {
  margin-top: 30px;
  width: auto;
  height: 551px;
}
.wds-frame-form-item{
  max-height: 40px;
  padding-top: 6px;
  padding-left: 4px;
  line-height: 20px !important;
  color: #054999;
}
.button{
  margin-top: 15px;
  margin-left: 50px;
}
</style>
